package Service;

import Dao.AccountDao;
import Entity.Account;

import java.util.List;

public class AccountService {
    private AccountDao accountDao;
    private float fromAccountMoney;
    private float toAccountMoney;
    public  String jiajian(Account fromAccount,Account toAccount,float money){
        fromAccountMoney = fromAccount.getMoney();
        toAccountMoney = toAccount.getMoney();
           fromAccountMoney =  fromAccountMoney - money;
          fromAccount.setMoney(fromAccountMoney);
          accountDao.updateAccount(fromAccount);
           if (true){
               throw new RuntimeException("发生了异常");
           }else {
               toAccountMoney = toAccountMoney+money;

           }
            toAccount.setMoney(toAccountMoney);
            accountDao.updateAccount(toAccount);
            return String.valueOf(money);

    }
    public Account getAccount(int id){
      return accountDao.getAccountById(id);
    }

    public List<Account> accountList(){
       return accountDao.accountList();
    }

    public AccountDao getAccountDao() {
        return accountDao;
    }

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }
}
